package com.gxgy.app.service.imp;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxgy.app.doman.po.Goods;
import com.gxgy.app.doman.po.User;
import com.gxgy.app.mapper.GoodsMapper;
import com.gxgy.app.mapper.UserMapper;
import com.gxgy.app.service.GoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {

    @Resource
    private UserMapper userMapper;
    @Override
    public List<Goods> goodsByClassify(Long id) {
        // 校验用户是否存在
        User user = userMapper.selectById(id);
        if(ObjectUtil.isNull(user)){
            throw new RuntimeException("用户不存在");
        }
        // 用户存在，通过分类查询对应的商品列表
        List<Goods> goodsList = this.list(new LambdaQueryWrapper<Goods>()
                .eq(Goods::getClassify, user.getBimClassify()));
        return goodsList;
    }
}
